<template>
	<view>
		<u-navbar :background="background" :borderBottom="false">
			<view class="ft_16 fw-b">
				积分商城
			</view>
		</u-navbar>
		<view class="content">
			<view class=" just_space tuijian" style="flex-flow: wrap;display: flex;">
				<shop v-for="(item,index) in shopList" :key="index" :shopimg="item.image" :shopname="item.name" :price="item.price" :jifen="item.prices" :num="item.sales" @click.native="go_shopList(item,index)"></shop>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	import shop from "../../../../components/jifenShop.vue"
	export default {
		data() {
			return {
				background:{backgroundColor: '#fafafa',},
				option:true, //默认排序
				option1:true, //销量排序
				option2:true, //价格排序
				
				shopList:[], //商品列表
				page:1, //默认获取页数
				
			}
		},
		components:{
			shop
		},
		onLoad() {
			this.getjifenList(1)
		},
		onReachBottom() {//触底获取商品
			this.page+=1
			console.log(this.page);
			this.getjifenList(this.page) 
		},
		methods: {
			getjifenList(page){ //获取积分商品列表
				this.$myRequest('goods/integralList',{
					page:page,num:20,
				}).then(res=>{
					console.log(res.data);
					if(res.data.data.goodslist.length<=0){
						this.$all.toast("没有更多了")
					}else{
						this.shopList.push(...res.data.data.goodslist)
						let user=this.$all.getData('userInfo').role_type //获取用户信息
						this.shopList.forEach(i=>{
							i.prices= user==0 ? i.prices : user==1 ? i.prices1 : user==2 ? i.prices2 :i.prices3
						})
					}
				})
			},
			
			go_shopList(item,index){ //去商品详情
				console.log(index);
				uni.navigateTo({
					url:"jifenDetail?shopid="+item.id
				})
			},
			
		}
	}
</script>

<style lang="scss">
page{
	background-color: #fafafa;
}
.content{
	padding: 15px;
	.options{
		padding: 15px 0;
		.option{
			padding-right: 25px;
		}
	}
}

</style>
